<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-merchantBank-edit" th:object="${merchantBank}">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
			<input id="merchantId" name="merchantId" th:field="*{merchantId}"  type="hidden">
			<div class="form-group">
				<label class="col-sm-3 control-label">银行类型：</label>
				<div class="col-sm-8">
					<select class="form-control" id="bankId" name="bankId">
						<option value="" selected>----请选择----</option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">分行：</label>
				<div class="col-sm-8">
					<input id="bankBranch" name="bankBranch" th:field="*{bankBranch}" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">支行：</label>
				<div class="col-sm-8">
					<input id="bankSubBranch" name="bankSubBranch" th:field="*{bankSubBranch}" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">所在省：</label>
				<div class="col-sm-8">
					<select class="form-control" id="bankProvince" name="bankProvince">
						<option value="" selected>----请选择----</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">所在市：</label>
				<div class="col-sm-8">
					<select class="form-control" id="bankCity" name="bankCity">
						<option value="" selected>----请选择----</option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">联行号：</label>
				<div class="col-sm-8">
					<input id="bankUnionNo" name="bankUnionNo" th:field="*{bankUnionNo}" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">持卡人：</label>
				<div class="col-sm-8">
					<input id="bankAccountOwner" name="bankAccountOwner" th:field="*{bankAccountOwner}" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">卡号：</label>
				<div class="col-sm-8">
					<input id="bankAccountNo" name="bankAccountNo" th:field="*{bankAccountNo}" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">账户类型：</label>
				<div class="col-sm-8">
					<select class="form-control" id="bankAccountType" name="bankAccountType">
						<option value="0">对私</option>
						<option value="1">对公</option>
					</select>
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script th:inline="javascript">
		var prefix = ctx + "merchant/merchantBank";
        var $form = $("#form-merchantBank-edit");
        var $province = $form.find("select[name='bankProvince']");
        var $city = $form.find("select[name='bankCity']");
        var merchantBank = [[${merchantBank}]];
        var banks = [[${banks}]];
        // 账户类型回显
        $form.find("select[name='bankAccountType']").val(merchantBank.bankAccountType).prop('selected',true);



        /*银行类型下拉框*/
        var option = "";
        for (var i = 0; i < banks.length; i++) {
            if (banks[i].id == merchantBank.bankId) {
                option += "<option selected='selected' value='"+ banks[i].id +"'>" + banks[i].name + "</option>"
			}else {
                option += "<option value='"+ banks[i].id +"'>" + banks[i].name + "</option>"
			}
        }
        $form.find("select[name='bankId']").html("").append(option);


        /*省市下拉框*/
        /*初始化-省*/
        $.post(ctx + "basedata/areas/list",{'levelType':1,'parentId':100000},function (response) {
            var data = response.rows;
            var option = "";
            for (var i = 0; i < data.length; i++){
                if (data[i].province == merchantBank.bankProvince) {
                    option += "<option selected='selected' value='" + data[i].province + "'>" + data[i].province + "</option>"
				}else {
                    option += "<option value='" + data[i].province + "'>" + data[i].province + "</option>"
				}
            }
            $province.html("").append(option);
            $form.find("select[name=bankProvince]").find("option[value="+ merchantBank.bankProvince +"]").prop('selected',true);
        });
        if (merchantBank.bankProvince) {
            getCityOrCounty(2, merchantBank.bankProvince, $city, $city.val());
		}
        /*省下拉框-选择事件*/
        var str="";
        $province.change(function () {
            $city.html(str);
            if ($province.val())
                getCityOrCounty(2, $province.val(), $city, $city.val());
        });
        /*根据省查询市*/
        function getCityOrCounty(LevelType,province,htm,address) {
            $.post(ctx + "basedata/areas/parentId", {'levelType':LevelType,'province':province}, function (response) {
                var data = response.rows;
                var option = "";
                for (var i = 0; i < data.length; i++) {
                    if (data[i].city == merchantBank.bankCity) {
                        option += "<option selected='selected'  value='" + data[i].city + "'>" + data[i].city + "</option>"
					}else {
                        option += "<option value='" + data[i].city + "'>" + data[i].city + "</option>"
					}
                }
                htm.html("").append(option);
            });
        }



        /*表单校验*/
		$("#form-merchantBank-edit").validate({
			rules:{
				xxxx:{
					required:true,
				}
			},
			focusCleanup: true
		});


		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/edit", $('#form-merchantBank-edit').serialize());
	        }
	    }
	</script>
</body>
</html>
